﻿#ifndef LOGTEXTSINK_H
#define LOGTEXTSINK_H

#include <vector>
#include <iostream>

#include <QString>
#include <QWidget>
#include <mutex>
#include <QTimer>
#include <QPlainTextEdit>
#include "glog/logging.h"

class LogTextSink : public QWidget, public google::LogSink
{
    Q_OBJECT
public:
    LogTextSink(QWidget* parent=NULL);
    virtual ~LogTextSink();

public:
    virtual void send(google::LogSeverity severity,
                      const char* full_filename,
                      const char* base_filename,
                      int line,
                      const struct tm* tm_time,
                      const char* message,
                      size_t message_len);

public slots:
    void refresh();

protected:
    QPlainTextEdit *log_widget_;
    QTimer timer_;
    std::mutex mutex_;

    typedef std::pair<std::string, google::LogSeverity> MessageType;
    std::vector<MessageType> message_vec_;

    const int MAXIMUM_BLOCK_COUNT;
    const int REFESH_TIME;
};

#endif

